<?php

declare(strict_types=1);
/**
 * This file is part of MoChat.
 * @link     https://mo.chat
 * @document https://mochat.wiki
 * @contact  group@mo.chat
 * @license  https://github.com/mochat-cloud/mochat/blob/master/LICENSE
 */
namespace MoChat\App\WorkDepartment\Job;

use Hyperf\AsyncQueue\Job;
use Hyperf\Logger\LoggerFactory;
use MoChat\App\WorkDepartment\Logic\SyncDepartmentDetailLogic;

/**
 * 根据企业ID和wx部门id同步部门详情.
 */
class SyncDepartmentDetailJob extends Job
{
    /**
     * @var array
     */
    public $params;

    public function __construct(array $params)
    {
        $this->params = $params;
    }

    public function handle()
    {
        $corpId = (int) $this->params['corpId'];
        $wxDepartmentId = (int) $this->params['wxDepartmentId'];
        $lastDepartment = (int) $this->params['lastDepartment'];

        $loggerFactory = make(LoggerFactory::class);
        $logger = $loggerFactory->get(__CLASS__);
        $logger->debug(sprintf('同步部门详情队列开始, 企业ID:%s, 部门ID:%s', (string) $corpId, (string) $wxDepartmentId));

        $syncDepartmentDetailLogic = make(SyncDepartmentDetailLogic::class);
        $syncDepartmentDetailLogic->handle($corpId, $wxDepartmentId, $lastDepartment);
    }
}
